package day1;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.function.Consumer;

public class ArrayListDemo {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<String>();
        list.add("zhangsan");
        list.add(0,"lisi");
        list.add("wangwu");


        System.out.println("------------1-----------");
        for(int i=0; i<list.size(); i++){
            String s = list.get(i);
            System.out.println(s);
        }

        System.out.println("------------2----------");
        for(String obj : list){
            System.out.println(obj);
        }

        System.out.println("------------3----------");
        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()){
            String next = iterator.next();
            System.out.println(next);
        }

        System.out.println("------------4 lambda表达式（函数 表达式）----------");
        //Consumer
        list.forEach(new Consumer<String>() {
            @Override
            public void accept(String name) {
                System.out.println(name);
            }
        });

        list.forEach(( name)-> System.out.println(name));

        list.forEach(System.out::println);

    }

}
